/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package quanlisinhvien.bll;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import quanlisinhvien.dal.LopDAO;
import quanlisinhvien.dto.KhoaDTO;
import quanlisinhvien.dto.LopDTO;

/**
 *
 * @author Marshmallow
 */
public class LopBLL {
    
    private LopDAO lopDAO;

    public LopBLL() {
        this.lopDAO = new LopDAO();
    }
    
    public List<LopDTO> LayDanhSachLop(){
        try{
            List<LopDTO> danhSach = new ArrayList<LopDTO>();
            ResultSet rs = this.lopDAO.LayDanhSachLop();
            while (rs.next()){
                LopDTO lop = new LopDTO();
                lop.setMaLop(rs.getInt("maLop"));
                lop.setTenLop(rs.getString("tenLop"));

                KhoaDTO khoa = new KhoaDTO();
                khoa.setMaKhoa(rs.getInt("maKhoa"));
                lop.setKhoa(khoa);

                danhSach.add(lop);
            }
            return danhSach;
        }
        catch (Exception ex){
            System.out.println("From LopBLL: " + ex.getMessage());
            return null;
        }
    }
    
    public List<LopDTO> LayDanhSachLopTheoKhoa(String tenKhoa){       
        try{
            List<LopDTO> danhSach = new ArrayList<LopDTO>();
            ResultSet rs = this.lopDAO.LayDanhSachLopTheoKhoa(tenKhoa);
            while (rs.next()){
                LopDTO lop = new LopDTO();
                lop.setMaLop(rs.getInt("maLop"));
                lop.setTenLop(rs.getString("tenLop"));

                KhoaDTO khoa = new KhoaDTO();
                khoa.setMaKhoa(rs.getInt("Lop.maKhoa"));
                lop.setKhoa(khoa);

                danhSach.add(lop);
            }
            return danhSach;
        }
        catch (Exception ex){
            System.out.println("From LopBLL: " + ex.getMessage());
            return null;
        }
    }
}
